package pri.damai.xiaowu.auth.security.handle;

import pri.damai.xiaowu.auth.enums.ResultEnum;
import pri.damai.xiaowu.auth.utils.HttpUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;
import pri.damai.xiaowu.common.core.vo.ResultVO;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 认证失败异常处理器
 * @Desc
 * @Author DaMai
 * @Date 2021/7/15 13:02
 * 但行好事，莫问前程。
 */
@Slf4j
@Component
public class RuiRuanAuthenticationFailureHandler implements AuthenticationFailureHandler {

    @Autowired
    ApplicationContext context;

    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException {
        ResultVO<Object> resultVO = ResultVO.error(ResultEnum.LOGIN_FAIL.code(), exception.getMessage());
        HttpUtil.respJson(response,resultVO);
    }

}
